/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.util.Iterator;
import java.util.Set;
import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import modelo.JlistModeloPedidos;
import pojos.Albaran;
import pojos.Lineasalb;


/**
 *
 * @author Alejandrolpz
 */
public class JDialogVisualizarAlbaran extends javax.swing.JDialog {

    /**
     * Creates new form JDialog
     */
    Albaran albaranVisualizar;
  
    DefaultListModel modeloLista=new DefaultListModel();
    
    public JDialogVisualizarAlbaran(JPanel panelPadre,Albaran albaranVisualizar) {
        initComponents();
        this.setModal(true);
        
        this.albaranVisualizar=albaranVisualizar;
        this.setLocationRelativeTo(panelPadre);
        this.setTitle("Visualización Albaran");
        rellenarAlbaran();
        
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPinfoAlbaran = new javax.swing.JPanel();
        jLcodPedido = new javax.swing.JLabel();
        jLNumCodPedido = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLtextoCliente = new javax.swing.JLabel();
        jParticulosAlbaran = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListArticulosPedido = new javax.swing.JList();
        jPimporteTotalAlbaran = new javax.swing.JPanel();
        jLimportePedido = new javax.swing.JLabel();
        jLcantidadImporteTotal = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Visualizar Albaran"); // NOI18N
        setPreferredSize(new java.awt.Dimension(620, 510));
        setResizable(false);
        getContentPane().setLayout(null);

        jPinfoAlbaran.setBorder(javax.swing.BorderFactory.createTitledBorder("Información Albaran"));
        jPinfoAlbaran.setLayout(new java.awt.GridLayout(2, 2));

        jLcodPedido.setText("Código de Albaran");
        jPinfoAlbaran.add(jLcodPedido);

        jLNumCodPedido.setText("0");
        jPinfoAlbaran.add(jLNumCodPedido);

        jLabel5.setText("Cliente");
        jPinfoAlbaran.add(jLabel5);
        jPinfoAlbaran.add(jLtextoCliente);

        getContentPane().add(jPinfoAlbaran);
        jPinfoAlbaran.setBounds(10, 11, 610, 140);

        jParticulosAlbaran.setBorder(javax.swing.BorderFactory.createTitledBorder("Articulos Albaran"));
        jParticulosAlbaran.setLayout(new java.awt.GridLayout(1, 0));

        jScrollPane1.setViewportView(jListArticulosPedido);

        jParticulosAlbaran.add(jScrollPane1);

        getContentPane().add(jParticulosAlbaran);
        jParticulosAlbaran.setBounds(10, 170, 600, 180);

        jPimporteTotalAlbaran.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPimporteTotalAlbaran.setLayout(new java.awt.GridLayout(1, 0));

        jLimportePedido.setText("Importe Total del Pedido :");
        jPimporteTotalAlbaran.add(jLimportePedido);

        jLcantidadImporteTotal.setText("0");
        jPimporteTotalAlbaran.add(jLcantidadImporteTotal);

        getContentPane().add(jPimporteTotalAlbaran);
        jPimporteTotalAlbaran.setBounds(10, 370, 600, 40);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rellenarAlbaran()
    {
        String codAlbaran=this.albaranVisualizar.getCodAlbaran().toString();
        this.jLNumCodPedido.setText(codAlbaran);
        
        String codCliente=this.albaranVisualizar.getCliente().getIdCliente().toString();
        this.jLtextoCliente.setText(codCliente);
        
        Integer importeAlbaran=this.albaranVisualizar.getImporteTotal();
        this.jLcantidadImporteTotal.setText(importeAlbaran.toString());
      
        
        Iterator listaLineas=this.albaranVisualizar.getLineasalbs().iterator();
       
        while(listaLineas.hasNext()) {
            Lineasalb nuevaLinea=(Lineasalb)listaLineas.next();
            Integer importe=nuevaLinea.getImporte();
            Integer cantidad=nuevaLinea.getCantidad();
           
            JlistModeloPedidos nuevoElmento=new JlistModeloPedidos(nuevaLinea.getArticulos(),importe.toString(),cantidad.toString());
            this.modeloLista.addElement(nuevoElmento);
           
        }
        
        this.jListArticulosPedido.setModel(modeloLista);
                
    }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLNumCodPedido;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLcantidadImporteTotal;
    private javax.swing.JLabel jLcodPedido;
    private javax.swing.JLabel jLimportePedido;
    private javax.swing.JList jListArticulosPedido;
    private javax.swing.JLabel jLtextoCliente;
    private javax.swing.JPanel jParticulosAlbaran;
    private javax.swing.JPanel jPimporteTotalAlbaran;
    private javax.swing.JPanel jPinfoAlbaran;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
